SYS_NAME=test

MAINPATH=$(shell /bin/pwd)
CPROJECTPATH=$(MAINPATH)/CProject
COMMONPATH=$(MAINPATH)/Common
TESTPATH=$(MAINPATH)/TestProject
BINARY=binary

INCLUDES=-I$(CPROJECTPATH)/headers -I$(COMMONPATH)/headers
vpath %.c CProject/sources
vpath %.c $(COMMONPATH)/sources
vpath %.c TestProject/Test_files


SYSTEM_OBJECTS=$(BINARY)/Dual_Link_List.o \
               $(BINARY)/thread_routine.o \
               $(BINARY)/alarm_thread.o \
               $(BINARY)/alarm_data_mutex.o \
	       $(BINARY)/datapool_mutex.o \
	       $(BINARY)/data_read_thread.o \
	       $(BINARY)/data_process_thread.o \
 	       $(BINARY)/data_write_thread.o \
		   $(BINARY)/insert_alarm.o	\
		   $(BINARY)/tcp_server.o	\
		   $(BINARY)/tcp_client.o	\
		   $(BINARY)/udp_server.o	\
		   $(BINARY)/udp_client.o	\
		   $(BINARY)/parallel_tcp_server.o

UNITTEST_OBJECTS=$(BINARY)/CreateLinkListHelper.o \
	         $(BINARY)/PrintDataHelper.o \
	         $(BINARY)/test.o

SUN_STUDIO = /usr
SUN_STUDIO_PREFIX = $(SUN_STUDIO)
CFLAGS=$(INCLUDES) -g 
CC = $(SUN_STUDIO_PREFIX)/bin/gcc
CXX = $(SUN_STUDIO_PREFIX)/bin/g++
MKDIR=mkdir

all : $(BINARY) $(SYS_NAME) assist_test

$(BINARY):
	$(MKDIR) $(BINARY)

$(SYS_NAME): $(SYSTEM_OBJECTS) $(UNITTEST_OBJECTS)
	$(CC) -o $(SYS_NAME) $(SYSTEM_OBJECTS) $(UNITTEST_OBJECTS) -lpthread

$(BINARY)/%.o : %.c 
#	$(CC) $(CFLAGS) -c $< -o $@
	$(CC) $(CFLAGS) -o $@ -c $<
	
assist_test: $(BINARY)/assist_test.o $(BINARY)/tcp_server.o $(BINARY)/udp_server.o $(BINARY)/parallel_tcp_server.o
	gcc -o assist_test $(BINARY)/assist_test.o $(BINARY)/tcp_server.o $(BINARY)/udp_server.o $(BINARY)/parallel_tcp_server.o

clean:
	rm -rf $(SYS_NAME) $(BINARY)
	rm -rf assist_test
